package com.wwl.cms.utils.designModeTest.state;

import java.util.Random;

/**
 * @author wwl
 * @version 1.0
 * @date 2021/9/27 10:49
 * @description:
 */
public class CanRaffleState extends State {

    RaffleActivity activity;

    public CanRaffleState(RaffleActivity activity) {
        this.activity = activity;
    }
    @Override
    public void deductMoney(){
        System.out.println("已经扣取过了积分");
    }

    //可以抽奖，抽完奖后，根据实际情况，改成新的状态
    @Override
    public boolean raffle(){
        System.out.println("正在抽奖，请稍后！");
        Random r = new Random();
        int num = r.nextInt(10);
        //10%中奖机会
        if(num==0){
            //改变活动状态为发放奖品
            activity.setState(activity.getDispenseState());
            return true;
        }else{
            System.out.println("很遗憾没有抽中奖品！");
            activity.setState(activity.getNoRafflleState());
            return false;
        }
    }

    @Override
    public void dispensePrize(){
        System.out.println("没中奖，不能发放奖品！");
    }
}
